#include "visit.h"

/*!
 *@brief 访问基本表达式primaryExp
 *@param node AST节点指针
 *@param s 符号表指针
 *@param bb 基本块指针
 *@return variant<int, float, string>类型
 *
 * 其中int和float是可能的整数或小数
 *
 * string类型是标识符
 *@note 使用
    if(auto pval = std::get_if<int>(&v))
        int value = *pval;
    else if(auto pval = std::get_if<float>(&v))
        float value = *pval;
    else
        string ident = *pval;
 */
variant<int, float, string> visit_primaryExp(ASTNode* node, SymbolTable* s, BasicBlock* bb) {
    if (!node){
        variant<int, float, string> res;
        res = 0;
        return res;
    }
    

    ASTNode* child = node->children[0];
    if (child->type == "number") {
        // 处理数字
        variant<int, float> number = visit_number(node->children[0], s, bb);
        variant<int, float, string> new_number;

        if(auto pval = std::get_if<int>(&number))
            new_number = *pval;
        else if(auto pval = std::get_if<float>(&number))
            new_number = *pval;

        return new_number;
    } else if (child->type == "lVal") {
        // 处理变量
        // visit_lVal(node->children[0], s, bb);
    } else if (child->type == "(") {
        // 处理表达式
        // visit_exp(node->children[1], s, bb);
    }
}